package tutorial.api.new_api.xls;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import public_util.model.Const4PublicDataBase;
import public_util.model.ReturnData;
import public_util.servlet.ServletParent;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


@Controller("/application_4_tutorial_xls")
public class Tutorial4XlsServlet extends ServletParent {

    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(Tutorial4XlsServlet.class);




    /**
     * @see HttpServlet#HttpServlet()
     */
    public Tutorial4XlsServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }



    /**
     */
    @RequestMapping("/application_4_tutorial_xls")
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String methodName = request.getParameter(Const4PublicDataBase.PARA_invoke_method);
        if (methodName!= null)
        {
            logger.info("--2--");
            super.doPost(request, response);
            return;
        }
        logger.info("--1--");

        //--提前打印出来
        ReturnData data  = new ReturnData();

        data.setStatus(0);
        printRes(response, data);
    }



    /**
     * 测试URL: application_4_tutorial_xls?invoke_method=show_xls_export
     */
    public void show_xls_export(HttpServletRequest request, HttpServletResponse response) {

        logger.info("----import_connection_data_from_xls----");


        Map<String, String[]> maps = request.getParameterMap();
        Map<String, String[]> new_map = new HashMap<String, String[]>();
        new_map.putAll(maps);
        ReturnData returnData = Tutorial4XlsTool.show_xls_export(getSqlSession(), this, response, request, new_map);
        if (returnData.getStatus() != 0)
        {
            printRes(response, returnData);
            return;
        }
        printRes(response, returnData);
    }


    /**
     * 测试URL: application_4_tutorial_xls?invoke_method=api_process_entrance&id_public_export_file_2_server=1
     */
    public void api_process_entrance(HttpServletRequest request, HttpServletResponse response) {

        logger.info("----api_process_entrance----");
        ReturnData returnData = Tutorial4XlsTool.api_process_entrance(getSqlSession(), this, response, request);
        if (returnData.getStatus() != 0)
        {
            printRes(response, returnData);
            return;
        }
        printRes(response, returnData);
    }

}